package display {
	import flare.vis.data.Data;
	import flare.vis.data.EdgeSprite;
	import flare.vis.data.NodeSprite;
	
	import flash.display.Sprite;
	import flash.display.Stage;
	
	import org.aswing.AsWingManager;
	import org.aswing.BorderLayout;
	import org.aswing.BoxLayout;
	import org.aswing.Container;
	import org.aswing.JFrame;
	import org.aswing.JList;
	import org.aswing.JScrollPane;
	
	import util.TextMarquee;

	public class GraphSummarySprite extends Sprite {
		public var frame:JFrame;
		public var text:JList;
		public var news:JList;
		public var marquee:TextMarquee;
		public function GraphSummarySprite(stage:Stage) {
			super();
			AsWingManager.setRoot(stage);
			frame = new JFrame(null, 'Summary');
			frame.setClosable(false);
			frame.setResizable(false);
			frame.setDragable(false);
			frame.setSizeWH(230, 210);
			frame.setX(0);
			frame.setY(115);
			
			var pane:Container = frame.getContentPane();
			pane.setLayout(new BoxLayout(BoxLayout.Y_AXIS, 0));
			
			var scroll:JScrollPane = new JScrollPane();
			
			text = new JList();
			scroll.setView(text);
			
			pane.append(scroll);
			
			var list:Array = [
				'Angela has updated her blog',
				'Bob upload a new video',
			    'David send a new email',
				'Carol update her blog',
				'Eve update her buzz',
				];
			scroll = new JScrollPane();
			news = new JList(list);
			scroll.setView(news);
//			pane.append(scroll, BorderLayout.SOUTH);
			pane.append(scroll);
		}
		public function update(data:Data):void {
			var avgDegree:Number = 0;
			var avgPopularity:Number = 0;
			var avgDistance:Number = 0;
//			new NodeSprite
			new EdgeSprite
			for each (var node:NodeSprite in data.nodes) {
				avgDegree += node.childDegree;
				avgPopularity += node.data.popularity;
			}
			for each (var edge:EdgeSprite in data.edges) {
				avgDistance += edge.data.distance;
			}
			avgDegree /= data.nodes.length;
			avgPopularity /= data.nodes.length;
			avgDistance /= data.edges.length;
			avgDegree = Math.round(avgDegree * 100) / 100;
			avgPopularity = Math.round(avgPopularity * 100) / 100;
			avgDistance = Math.round(avgDistance * 100) / 100;
			var list:Array = [];
			list.push("Total Friends: " + data.nodes.length);
			list.push("Average Degree: " + avgDegree);
			list.push("Average Popularity: " + avgPopularity);
			text.setListData(list);
			frame.show();
			// averageDistanceLabel.text = "Average Distance: " + avgDistance;
		}
	}
}